<!DOCTYPE html>
<html lang="zh-cn">
	<head>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
	    <#include "/common/meta.ftl"/>
	    <link rel="stylesheet" href="${_b}/static/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
	    <script type="text/javascript" src="${_b}/static/zTree_v3/js/jquery.ztree.all.js"></script>
	    <#include "/common/form.ftl"/>
	    
		<script>
		var setting = {
				async: {
					enable: true,
					url: "./organTreeForUser"
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					onClick: function(event, treeId, treeNode){
						$("#organID").val(treeNode.id);
						$("#organID_V").val(treeNode.name);
						hideMenu();
					}
				}
			};
		$(function(){
				$("#form").validate({
					rules: {
						userName: {required:true,maxlength:228},
						userLoginName: {required:true,maxlength:228,
						remote:{
									cache : false,
					          		type:"POST",
					               	url:"./loginNameExsit",
					               	data:{
					               		userID : function(){return $("#userID").val();},
					             		userLoginName : function(){return $("#userLoginName").val();},
					             		noCache : function(){return Math.random();}
					               	} 
				              	} 		
              			},
              			userPwd: {required:true,maxlength:10},
              			userPwd2: {required:true,maxlength:10,equalTo:"#userPwd"},
						organID_V: {required:true,maxlength:208}
					},
					messages: {
						userLoginName:{remote:" 该登录名已存在"}
					},
					errorElement: "div",
					errorPlacement: function(error, element) {
						error.appendTo($(element).parent());
						$(element).parent().addClass("has-error");
						$(error).addClass("help-block alert-danger");
					},
					success: function(label) {
						$(label).parent().removeClass("has-error");
						$(label).remove();
					}
				})
			});
			
			function showMenu() {
				$.fn.zTree.init($("#organForSelect"), setting);
				var cityObj = $("#organID_V");
				var cityOffset = $("#organID_V").offset();
				$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() - 8 + "px"}).slideDown("fast");
	
				$("body").bind("mousedown", onBodyDown);
			}
			function hideMenu() {
				$("#menuContent").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDown);
			}
			function onBodyDown(event) {
				if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
					hideMenu();
				}
			}
			function save(){
				if($("#form").valid()){
					
					$("#form").submit();
				}
			}
		</script>
	</head>
	<body style="padding:5px;">
		<div id="menuContent" class="menuContent" style="display:none; position: absolute;z-index:1000000000000;">
			<ul id="organForSelect" class="ztree form-control" style="margin-top:0;margin-top: 10px;overflow-y:scroll;height:290px;background: #f0f6e4;padding-right:20px;width:260px;"></ul>
		</div>
		<div class="panel panel-primary">
			<div class="panel-heading" style="">
				<strong>
				<#if (userID!'')!=''><i class="icon-pencil"></i> 编辑<#else><i class="icon-plus"></i> 添加</#if>用户
				</strong>
			</div>
		
			<div class="panel-body" style="padding:5px;padding-top:15px;">
			<form id="form" class="form-horizontal" role="form" method='post' action="./userSave">
			<input type="hidden" name="userID" id ="userID" value="${userID?default('')}"/>
        		<div class="form-group">
          			<label class="col-sm-2  control-label required" >登录名</label>
	          		<div class="col-sm-3 ">
	             		<input type='text' name="userLoginName"  id='userLoginName' value='<#if formData?exists>${formData.userLoginName!''}</#if>' class='form-control' placeholder=''/>
	          		</div>
	          		<label class="col-sm-2  control-label required" >用户名</label>
	          		<div class="col-sm-3">
	             		<input type='text' id="userName" name="userName" value='<#if formData?exists>${formData.userName!''}</#if>' class='form-control' placeholder=''/>
	          		</div>
        		</div>
        		<#if (userID!'')==''>
        		<div class="form-group">
          			<label class="col-sm-2 control-label required" >密码</label>
	          		<div class="col-sm-3">
	             		<input type='password'  name="userPwd" id='userPwd' value='' class='form-control' placeholder=''/>
	          		</div>
	          		<label class="col-sm-2 control-label required" >确认密码</label>
	          		<div class="col-sm-3">
	             		<input type='password'  name="userPwd2" id='userPwd2' value='' class='form-control' placeholder=''/>
	          		</div>
        		</div>
        		</#if>
        		<div class="form-group">
          			<label class="col-sm-2  control-label" >组织机构</label>
	          		<div class="col-sm-3">
	          			<input type="hidden" id="organID" name="organID" value="<#if formData?exists>${formData.organID!''}</#if>"/>
	             		<input type='text' id='organID_V' name="organID_V" readonly onclick="showMenu(); return false;" value='<#if organName?exists>${organName!''}</#if>' class='form-control' placeholder=''/>
	          		</div>
	          		<label class="col-sm-2  control-label" >性别</label>
	          		<div class="col-sm-1">
	          		<select name='userSex' id='userSex' class='form-control'>
	             			<#assign o = 1/>
	             			<#if formData?exists>
	             				<#assign o = formData.userSex/>
	             			</#if>
			            	<option value="1" <#if o==1>selected</#if>>男</option>
							<option value="2" <#if o==2>selected</#if>>女</option>
			            </select>
	          		</div>
        		</div>        		
        		<div class="form-group">
          			<label class="col-sm-2 control-label " >手机号码</label>
	          		<div class="col-sm-3">
	             		<input type='text' name="userMobile"  id='userMobile' value='<#if formData?exists>${formData.userMobile!''}</#if>' class='form-control' placeholder=''/>
	          		</div>
	          		<label class="col-sm-2  control-label " >办公电话</label>
	          		<div class="col-sm-3">
	             		<input type='text' id="userPhone" name="userPhone" value='<#if formData?exists>${formData.userPhone!''}</#if>' class='form-control' placeholder=''/>
	          		</div>
        		</div>     
        		<div class="form-group">
          			<label class="col-sm-2 control-label " >电子邮箱</label>
	          		<div class="col-sm-3">
	             		<input type='text' name="userEmail"  id='userEmail' value='<#if formData?exists>${formData.userEmail!''}</#if>' class='form-control' placeholder=''/>
	          		</div>
	          		<label class="col-sm-2  control-label required" >排序</label>
	          		<div class="col-sm-1">
	             		<input type='text' id="userOrder" name="userOrder" value='<#if formData?exists>${formData.userOrder!''}<#else>10</#if>' class='form-control' placeholder=''/>
	          		</div>
        		</div>    
        		
        		<div class="form-group">
          			<label class="col-sm-2  control-label " >出生日期</label>
	          		<div class="col-sm-3">
	             		<input type='text' name="userBirthday"  id='userAddress' value='<#if formData?exists>${formData.userBirthday!''}</#if>' class='form-control' placeholder=''/>
	          		</div>
	          		<label class="col-sm-2  control-label " >状态</label>
	          		<div class="col-sm-1">
						<select name='userStatus' id='userStatus' class='form-control'>
	             			<#assign o = 1/>
	             			<#if formData?exists>
	             				<#assign o = formData.userStatus/>
	             			</#if>
			            	<option value="1" <#if o==1>selected</#if>>正常</option>
							<option value="11" <#if o==11>selected</#if>>未激活</option>
							<option value="2" <#if o==2>selected</#if>>停用</option>
			            </select>	          		
			            </div>
	          		
        		</div> 
        		<div class="form-group">
          			<label class="col-sm-2  control-label" >地址</label>
	          		<div class="col-sm-8">
	             		<input type='text' name="userAddress"  id='userAddress' value='<#if formData?exists>${formData.userAddress!''}</#if>' class='form-control' placeholder=''/>
	          		</div>
	          		
        		</div>   		
        		<div class="form-group">
		          	<div class="col-sm-offset-2 col-sm-10">
		             	<button class="btn btn-primary" onclick="save();" type="button"><i class="icon icon-save"></i> 保存</button>
		             	<#if (userID!'')!=''>
		             	<button class="btn btn-danger" type="button" onclick="location.href='./editpasswd?userID=${userID}'"><i class="icon icon-pencil"></i> 修改密码</button>
		             	</#if>
		             	<button class="btn" type="button" onclick="location.href='./userForList'"><i class="icon icon-reply"></i> 返回</button>
		          	</div>
		        </div>
        		</form>
		  	</div>
		</div>
	</body>
</html>